#include "../include/ui/mainwindow.h"
#include "../include/freeda.h"
#include "../include/utils.h"

Freeda::Freeda(string stdPath) {
    if (!stdPath.empty())
        this->setCurrentDir(new Dir(stdPath));
    else
        this->setCurrentDir(new Dir(libfm::getHome()));
}

void Freeda::setCurrentDir(Dir *dir) {
    this->currentDir = dir;
    libfm::setCurrentPath(dir->path);
}

void Freeda::start() {
    while (true) {
        Entity* result = MainWindow::pickItem(this->currentDir);
        
        if (result) {
            Dir* dir = dynamic_cast<Dir*>(result);
            if (dir && dir->getItems().size() > 0)
                this->setCurrentDir(dir);
        } else {
            break;
        }
    }
    endwin();
}

int main(int argc, char *argv[]) {
    string stdPath = "";
    if (argc > 1) {
        stdPath = argv[1];
    }

    Freeda fr = Freeda(stdPath);
    fr.start();

    return 0;
}

